<style>
    #notice-add {
        padding: 20px 25px 25px 0;
    }
</style>
<div class="layui-fluid" id="notice-add">
    <form class="layui-form" action="" lay-filter="college-add-form">

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label febs-form-item-require">通知图片：</label>
            <div class="layui-upload">
                <div class="layui-upload-list">
                    <img class="layui-upload-img" src="" id="notice-add-img1" width="200px" height="150px">
                    <input type="hidden" id="myimg" name="imgUrl">
                    <p id="demoText"></p >
                </div>
                <a id="notice-add-test1" style="padding-left: 110px">上传图片</a>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">通知标题：</label>
            <div class="layui-input-block">
                <input type="text" name="title" minlength="2" maxlength="50"
                       autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公司名：</label>
            <div class="layui-input-block">
                <input type="text" data-th-value="陕西全务"
                       autocomplete="off" class="layui-input" readonly="true" style="background:#F0F0F0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建人：</label>
            <div class="layui-input-block">
                <input type="text" name="UserName" data-th-value="${username}"
                       autocomplete="off" class="layui-input" readonly="true" style="background:#F0F0F0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建日期：</label>
            <div class="layui-input-block">
                <input type="text" disabled="true"
                       autocomplete="off" class="layui-input" id="currentTime" readonly="true" style="background:#F0F0F0">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">通知内容：</label>
            <div class="layui-input-block">
                <textarea name="content" maxlength="100" class="layui-textarea" lay-verify="required"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">通知视频：</label>
            <div class="layui-upload">
                <div class="layui-upload-list">
                    <video class="layui-upload-video" src="" id="notice-add-video1" controls="controls" width="200px" height="150px">
                    </video>
                    <input type="hidden" id="notice-add-myvideo" name="videoUrl">
                    <p id="videoText"></p >
                </div>
                <a id="notice-add-testVideo" style="padding-left: 110px">上传视频</a>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">通知附件：</label>
            <div class="layui-upload">
                <div class="layui-upload-list">
                    <file  class="layui-upload-file" src="" id="notice-add-file1" width="200px" height="150px"></file>
                    <input type="hidden" id="notice-add-myfile" name="myfile">
                    <p id="fileText"></p >
                </div>
                <a id="notice-add-testfile">上传附件</a>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-md10">
                <div class="layui-form-item">
                    <label class="layui-form-label febs-form-item-require">接收人：</label>
                    <div class="layui-input-block">
                        <input type="text" id="noticereceive" autocomplete="off"
                               class="layui-input" lay-verify="required" readonly="true" style="background:#F0F0F0">
                    </div>
                </div>
            </div>
            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                <!--出现一个加号-->
                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="student" style="margin-left: 10px">
                    <i class="layui-icon">&#xe624;</i>
                </div>
                <!--出现一个减号-->
                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="resetUser">
                    <i class="layui-icon">&#xe67e;</i>
                </div>

            </div>
        </div>

        <!--隐藏的部分属性-->
        <div class="layui-form-item febs-hide">
            <label class="layui-form-label febs-form-item-require">接收人隐藏id：</label>
            <div class="layui-input-block">
                <input type="text" name="userIds" id="noticereceivehide">
            </div>
        </div>

        <div class="layui-form-item febs-hide">
            <label class="layui-form-label febs-form-item-require">创建人id：</label>
            <div class="layui-input-block">
                <input type="text" name="createUserId" data-th-value="${userId}">
            </div>
        </div>

        <div class="layui-form-item febs-hide">
            <label class="layui-form-label febs-form-item-require febs-hide">消息提交状态：</label>
            <div class="layui-input-block">
                <input type="text" name="status" id="status_Id">
            </div>
        </div>
        <div class="layui-form-item febs-hide">
            <button class="layui-btn" lay-submit="" lay-filter="notice-add-form-submit" id="submit"></button>
            <button class="layui-btn" lay-submit="" lay-filter="college-add-form-submitTemp" id="submitTemp"></button>
            <button type="reset" class="layui-btn" id="reset"></button>
        </div>
    </form>
</div>

<script>
    layui.use(['febs', 'form', 'xmSelect', 'validate', 'laydate','dropdown', 'jquery', 'table','upload'], function () {
        let $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            form = layui.form,
            laydate = layui.laydate,
            dropdown=layui.dropdown,
            jquery=layui.jquery,
            table=layui.table,
            upload = layui.upload,
            $view = $('#notice-add'),
            $student = $view.find('#student'),
            $resetUser = $view.find('#resetUser'),
            validate = layui.validate;

        form.verify(validate);
        form.render();

        laydate.render({
            elem: '#currentTime',
            type: 'datetime',
            value: new Date(),
            done: function (value, date) {
            }
        });
        //图片上传
        var uploadInst = upload.render({
            elem: '#notice-add-test1'
            ,url: ctx+'upload' //改成您自己的上传接口
            ,method:'post'
            ,auto:false
            ,accept:'images'
            ,exts: 'jpg|png|gif|bmp|jpeg'
            ,choose: function(obj){
                //预读本地文件示例，不支持ie8
                var flag = true;
                obj.preview(function(index, file, result){
                    var img = new Image();
                    img.src = result;
                    img.onload = function () { //初始化夹在完成后获取上传图片宽高，判断限制上传图片的大小。
                        if(img.width <=750 && img.height <=560){
                            $('#notice-add-img1').attr('src', result); //图片链接（base64）
                            obj.upload(index, file); //满足条件调用上传方法
                        }else{
                            flag = false;
                            layer.msg("您上传的小图大小必须小于750*560尺寸！");
                            return false;
                        }
                    }
                    return flag;
                });
            }
            ,done: function(res){
                //上传成功
                if(res.code == 200){
                    layer.msg('上传图片成功');
                    $("#myimg").val(res.url);
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
        //视频上传
        var uploadVideo = upload.render({
            elem: '#notice-add-testVideo'
            ,url: ctx+'upload' //改成您自己的上传接口
            ,method:'post'
            ,auto:false
            ,accept:'video'
            ,exts: 'mp4|avi'
            ,choose: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#notice-add-video1').attr('src', result);
                    obj.upload(index, file);
                });
            }
            ,done: function(res){
                //上传成功
                if(res.code == 200){
                    layer.msg('上传视频成功');
                    $("#notice-add-myvideo").val(res.url);
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#videoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadVideo.upload();
                });
            }
        });
        //附件上传
        var uploadFile = upload.render({
            elem: '#notice-add-testfile'
            ,url: ctx+'upload' //改成您自己的上传接口
            ,method:'post'
            ,auto:false
            ,accept:'file'
            ,exts: 'mp4|avi|jpg|png|gif|bmp|jpeg|doc|docx|txt|xlsx|pdf'
            ,choose: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#notice-add-file1').attr('src', result);
                    obj.upload(index, file);
                });
            }
            ,done: function(res){
                //上传成功
                if(res.code == 200){
                    layer.msg('上传附件成功');
                    $("#notice-add-myfile").val(res.url);
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#fileText');
                demoText.html('<span style="color: #FF5722;">上传附件失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadFile.upload();
                });
            }
        });

        var stu_id = new Array();
        var stu_stuname = new Array();
        //进入学生的页面跳转控制器
        $student.on('click',function () {
            var selectStudent= febs.modal.open('选择学生', 'student/list', {
                //area: $(window).width() <= 750 ? '95%' : '50%',
                area: ['100%', '100%'],
                btn: ['选择勾选结果', '选择本页结果','选择全部结果'],
                yes: function (index, layero) {
                    //stu_id.push($('#select-student').find('#stu_ids').val());

                    $('#select-student').find('#btnCheckResults').trigger('click');
                    stu_stuname.push($('#select-student').find('#stu_stunames').val());//放入数组name
                    stu_id.push($('#select-student').find('#stu_ids').val());//放入数组id
                    //绑定显示name
                    $("#noticereceive").val(stu_stuname);
                    //绑定显示id
                    $("#noticereceivehide").val(stu_id);


                },
                btn2: function (index, layero) {
                    $('#select-student').find('#btnPageResults').trigger('click');
                    stu_stuname.push($('#select-student').find('#stu_stunames').val());//放入数组name
                    stu_id.push($('#select-student').find('#stu_ids').val());//放入数组id
                    //绑定显示name
                    $("#noticereceive").val(stu_stuname);
                    //绑定显示id
                    $("#noticereceivehide").val(stu_id);

                },
                btn3: function (index, layero) {
                    $('#select-student').find('#btnAllResults').trigger('click');
                    stu_stuname.push($('#select-student').find('#stu_stunames').val());//放入数组name
                    stu_id.push($('#select-student').find('#stu_ids').val());//放入数组id
                    //绑定显示name
                    $("#noticereceive").val(stu_stuname);
                    //绑定显示id
                    $("#noticereceivehide").val(stu_id);
                },
                success: function(layero){
                    layero.find('.layui-layer-btn').css('text-align', 'center');
                },
            });

        });

        form.on('submit(notice-add-form-submit)', function (data) {
            febs.post(ctx + 'notice/add', data.field, function () {
                layer.closeAll();
                febs.alert.success('新增通知成功');
                $('#notice-list').find('#query').click();
            });
            return false;
        });

        /**
         * 修改
         */
        form.on('submit(college-add-form-submitTemp)', function (data) {
            console.log(data.field);
            febs.post(ctx + 'notice/addTemp', data.field, function () {
                layer.closeAll();
                febs.alert.success('保存草稿成功');
                $('#notice-list').find('#query').click();
            });
            return false;
        });
        //清空
        $resetUser.on('click',function () {
            document.getElementById("noticereceive").value ="";
            //全局的数组一把清除
            stu_id.splice(0);
            stu_stuname.splice(0);
        })
    });
</script>